package com.example.demo.core.util;

import org.apache.commons.lang3.RandomStringUtils;

import javax.sip.address.SipURI;
import javax.sip.header.ToHeader;
import javax.sip.message.Request;
import java.util.UUID;

public class SipUtil {
    public static  String getNewViaTag() {
        return "z9hG4bK" + RandomStringUtils.randomNumeric(10);
    }

    public static String getNewFromTag(){
        return UUID.randomUUID().toString().replace("-","");
    }
    public static String getNewTag(){
        return String.valueOf(System.currentTimeMillis());
    }

    public static String getDeviceId(Request request){
        ToHeader toHead = (ToHeader) request.getHeader(ToHeader.NAME);
        SipURI toUri = (SipURI) toHead.getAddress().getURI();
        return toUri.getUser();
    }
}
